//
//  LBZhutiCourseCollectionViewCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBZhutiCourseCollectionViewCell.h"

@interface LBZhutiCourseCollectionViewCell ()

@property (nonatomic, strong) UIImageView *leftIcon;

@property (nonatomic, strong) UIImageView *leftBgimageView;
@property (nonatomic, strong) UILabel *leftLab;
@end
@implementation LBZhutiCourseCollectionViewCell
- (UIImageView *)leftBgimageView{
    if (!_leftBgimageView ) {
        _leftBgimageView = [[UIImageView alloc] init];
    }
    return _leftBgimageView;
}
- (UILabel *)leftLab{
    if (!_leftLab) {
        _leftLab = [UILabel labelWithText:@"主题课程第一季" andTextColor:rgb(51,51,51) andName:nil andFontSize:10*kScaleFit];
    }
    return _leftLab;
}
- (UIImageView *)leftIcon{
    if (!_leftIcon) {
        _leftIcon = [[UIImageView alloc] init];
    }
    return _leftIcon;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self = [[NSBundle mainBundle]loadNibNamed:@"LBZhutiCourseCollectionViewCell" owner:self options:nil].lastObject;
        
    }
    return self;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = [UIColor clearColor];
    
    self.leftBgimageView.frame = CGRectMake(20*kScaleFit, 0, 130*kScaleFit, 166*kScaleFit);
    [self.contentView addSubview:self.leftBgimageView];
    self.leftBgimageView.image = [UIImage imageNamed:@"tree_left"];
//    [self.leftBgimageView makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self.contentView);
//        make.bottom.mas_equalTo(-45*kScaleFit);
//        make.size.mas_equalTo(CGSizeMake(130*kScaleFit, 166*kScaleFit));
//    }];
    

    [self.leftBgimageView addSubview:self.leftIcon];
//    self.leftIcon.layer.cornerRadius = 5;
//    self.leftIcon.layer.masksToBounds = YES;
    self.leftIcon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    
    CGRect rect = CGRectMake(0, 0, 109, 67);
    CGSize radio = CGSizeMake(5, 5);//圆角尺寸
    UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//这只圆角位置
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
    masklayer.frame = self.leftIcon.bounds;
    masklayer.path = path.CGPath;//设置路径
    
    self.leftIcon.layer.mask = masklayer;
    self.leftIcon.frame = CGRectMake(17*kScaleFit, 3*kScaleFit, 109*kScaleFit, 59*kScaleFit);
//    [self.leftIcon makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(4*kScaleFit);
//        make.height.mas_equalTo(54*kScaleFit);
//        make.left.mas_equalTo(18*kScaleFit);
//        make.right.mas_equalTo(-5*kScaleFit);
//    }];

    UIView *smallView = [UIView new];
    
    smallView.backgroundColor = [UIColor whiteColor];
    [self.leftBgimageView addSubview:smallView];
    
    smallView.frame = CGRectMake(17*kScaleFit, 59*kScaleFit, 109*kScaleFit, 21*kScaleFit);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:smallView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    
    maskLayer.frame = smallView.bounds;
    
    maskLayer.path = maskPath.CGPath;
    
    smallView.layer.mask = maskLayer;


//    self.leftLab.frame = CGRectMake(0, 5, CGRectGetMaxX(smallView.frame), 22);
    self.leftLab.textAlignment = NSTextAlignmentCenter;
    [smallView addSubview:self.leftLab];
    [self.leftLab makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.leftIcon);
        make.centerY.mas_equalTo(smallView);
    }];
}
- (void)setModel:(LBCourseOutputDTOListModel *)model{
    _model = model;

    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,model.courseImage];
    [self.leftIcon sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    self.leftLab.text = model.courseName;
}
@end
